﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace TinyCinema.UI.Pages.Schedule._Deal
{
    /// <summary>
    /// Interaction logic for FromBookedTicket.xaml
    /// </summary>
    public partial class FromBookedTicket : Page
    {
        public static Bussiness.Schedule.BookedPayment BookedPayment = new Bussiness.Schedule.BookedPayment();

        public static DependencyProperty ContentFrameSourceProperty = DependencyProperty.Register("pagContentFrameSource", typeof(Page), typeof(FromBookedTicket));
        public Page pagContentFrameSource
        {
            get { return (Page)GetValue(ContentFrameSourceProperty); }
            set { SetValue(ContentFrameSourceProperty, value); }
        }
        public FromBookedTicket()
        {
            InitializeComponent();
            BookedPayment.Messenger.Register<Bussiness.Schedule.Message.BookedTicketCanceled>(this, (s) =>
            {
                MessageBoxUtils.WPFMessageBox.Show((App.Current.FindResource("langMsgScheduleBookCanceled") as String), "", MessageBoxButton.OK);
            });
            BookedPayment.Messenger.Register<Bussiness.Schedule.Message.BookedTicketNotFound>(this, (s) =>
            {
                MessageBoxUtils.WPFMessageBox.Show((App.Current.FindResource("langMsgScheduleBookNotFound") as String), "", MessageBoxButton.OK);
            });
            BookedPayment.Messenger.Register<Bussiness.Schedule.Message.BookedTicketPurchased>(this, (s) =>
            {
                MessageBoxUtils.WPFMessageBox.Show((App.Current.FindResource("langMsgScheduleBookPurchased") as String), "", MessageBoxButton.OK);
            });
            BookedPayment.Messenger.Register<Bussiness.Schedule.Message.DeleteConfirmation>(this, (s) =>
            {
                s.Result = MessageBoxUtils.WPFMessageBox.Show((App.Current.FindResource("langMsgScheduleBookDelete") as String), "", MessageBoxButton.YesNo);
            });
            BookedPayment.Messenger.Register<Bussiness.Schedule.Message.Deleted>(this, (s) =>
            {
                MessageBoxUtils.WPFMessageBox.Show((App.Current.FindResource("langMsgScheduleBookDeleted") as String), "", MessageBoxButton.OK);
                txtIDInput.Clear();
            });
            BookedPayment.Messenger.Register<Bussiness.Schedule.Message.PayConfirmation>(this, (s) =>
            {
                s.Result = MessageBoxUtils.WPFMessageBox.Show((App.Current.FindResource("langMsgDealPay") as String), "", MessageBoxButton.YesNo);
            });
            BookedPayment.Messenger.Register<Bussiness.Schedule.Message.PayConfirmationOK>(this, (s) =>
            {
                (new Tickets()).ShowDialog();
                txtIDInput.Clear();
            });
            Loaded += FromBookedTicket_Loaded;
            Unloaded += FromBookedTicket_Unloaded;
        }

        void FromBookedTicket_Unloaded(object sender, RoutedEventArgs e)
        {
            BookedPayment.StopBookedTickedCheck();
        }

        void FromBookedTicket_Loaded(object sender, RoutedEventArgs e)
        {
            BookedPayment.StartBookedTickedCheck();
        }

        private void Clear(object sender, RoutedEventArgs e)
        {
            txtIDInput.Clear();
        }
    }
}
